package com.phone.client.controller;

import com.seventh.common.pojo.R;
import com.phone.client.poji.entry.TbClient;
import com.phone.client.poji.vo.ClientVo;
import com.phone.client.service.ClientService;
import com.phone.client.utils.OSSUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @program: clms-seventh
 * @description: Client的控制层
 * @author: 杨佳琪
 * @create: 2021-07-23 11:37
 **/
@RestController
@RequestMapping("client/cli")
@Api(tags="会员的控制层")
public class ClientController {
    @Resource
    private ClientService clientService;

    @ApiOperation("分页查询")
    @PostMapping("initClientTable/{currentPage}/{pageSize}")
    public R initClientTable(@ApiParam(value = "页码",name = "currentPage") @PathVariable("currentPage") Integer currentPage,@ApiParam(value = "条数",name = "pageSize") @PathVariable("pageSize") Integer pageSize,
                             @RequestBody ClientVo clientVo){
        return clientService.initClientTable(currentPage,pageSize,clientVo);
    }

    @ApiOperation("删除")
    @DeleteMapping("deleteClient/{id}")
    public R deleteClient(@PathVariable Integer id){
        return clientService.deleteClient(id);
    }

    @ApiOperation("修改")
    @PutMapping("updateClient")
    public R updateClient(@RequestBody TbClient tbClient){
        return clientService.updateClient(tbClient);
    }

    @ApiOperation("新增")
    @PostMapping("insertClient")
    public R insertClient(@RequestBody TbClient tbClient){
        return clientService.insertClient(tbClient);
    }

    @ApiOperation("修改的回显")
    @GetMapping("findById/{id}")
    public R findById(@PathVariable Integer id){
        return clientService.findById(id);
    }

    @PostMapping("selUsername")
    @ApiOperation("查询客户账号是否唯一")
    public R selUsername(@ApiParam("客户信息")@RequestBody TbClient tbClient){
        return clientService.selUsername(tbClient);
    }

    @PostMapping("selPhone")
    @ApiOperation("查询客户电话是否唯一")
    public R selPhone(@ApiParam("客户信息")@RequestBody TbClient tbClient){
        return clientService.selPhone(tbClient);
    }

    @PostMapping("selEmail")
    @ApiOperation("查询客户邮箱是否唯一")
    public R selEmail(@ApiParam("客户信息")@RequestBody TbClient tbClient){
        return clientService.selEmail(tbClient);
    }

    @PostMapping("upPicture")
    @ApiOperation("上传图片")
    public String upPicture(@ApiParam("客户信息")@RequestBody MultipartFile file){
        return OSSUtil.upload2(file);
    }

    @PostMapping("selCname")
    @ApiOperation("查询客户名称是否唯一")
    public R selCname(@ApiParam("客户信息")@RequestBody TbClient tbClient){
        return clientService.selCname(tbClient);
    }

    @PutMapping("change/{id}/{status}")
    @ApiModelProperty("更新用户状态")
    public R upStatus(@ApiParam("用户ID")@PathVariable("id") Integer id,
                      @ApiParam("用户状态值")@PathVariable("status") Integer status){
        return clientService.upStatus(id,status);
    }
    @ApiOperation("修改的回显")
    @GetMapping("selectOne")
    public R selectOne( Integer id){
        return clientService.findById(id);
    }
}



